package com.tools;/**
 * @program: SmbmsDemo
 * @description: 拦截器
 * @author: Mr.Kang
 * @create: 2020-06-03 11:02
 **/

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description:
 * @author 康康真滴暖
 * @date 2020-06-03 11:02
 */

public class SysInterceptor implements HandlerInterceptor {
    private static final Logger log= LogManager.getLogger(SysInterceptor.class);
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception{
        log.info("进入校验拦截器");
        //判断当前用户是否登录
        Object attribute =request.getSession().getAttribute(Constants.USER_SESSION);
        if (attribute!=null){
            log.info("用户已登录");
            //该用户已登录
            return true;
        }else {
            response.sendRedirect(request.getContextPath()+"/error.jsp");
        }
        return false;
    }
}
